'use strict';

var is = require('bpmn-js/lib/util/ModelUtil').is,
    getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;

// 用户选择框
var userField = require('../factory/UserEntryFactiory');

var candiateConfig = require('@/views/wf/cfg/candidate').candiateConfig

module.exports = function(group, element, translate) {

  var bo = getBusinessObject(element);

  if (!bo) {
    return;
  }

  if (is(element, 'camunda:Initiator') && !is(element.parent, 'bpmn:SubProcess')) {
    group.entries.push(userField({
      id : 'initiator',         // id不重复，可以覆盖
      label : translate('Initiator'),
      modelProperty : 'initiator',
      doSelectUser: candiateConfig.doSelect,   // 用户点击选择用户按钮回调事件
      get: function(element) {
        var initiator = ''
        if(element.businessObject.initiator) {
          var user = JSON.parse(element.businessObject.initiator)
          initiator = user.name
        }
        return {
          'initiator': initiator
        }
      }
    }));
  }
};
